const path = require("path");
const ejs = require("ejs");

function  compileEjs(cpnname, data){
  return new Promise((resolve, reject)=>{
    //1.获取当前模板路径
  const absolutePath = path.resolve(__dirname, `../template/${cpnname}`);

  //2.使用ejs编译模版
  ejs.renderFile(absolutePath, data, (err, result) => {
    if(err){
      reject(err);
      return;
    }
    resolve(result);
  })

  })
}


module.exports = compileEjs